package com.czxy.service;

import cn.itcast.commons.CommonUtils;
import com.czxy.dao.UserMapper;
import com.czxy.domain.User;
import com.czxy.utils.MyBatisUtils;

import java.util.List;

public class UserService {

    public User login(User user){

        UserMapper mapper = MyBatisUtils.getMapper(UserMapper.class);

        User loginU = mapper.login(user);

        MyBatisUtils.close();
        return loginU;

    }


    public void register(User user){
        UserMapper mapper = MyBatisUtils.getMapper(UserMapper.class);
        user.setUid(CommonUtils.uuid());

         mapper.insert(user);
         MyBatisUtils.commitAndClose();

    }



    public List<User> findUserByUsername(String username){
        UserMapper mapper = MyBatisUtils.getMapper(UserMapper.class);
        List<User> users = mapper.findUserByUsername(username);

        MyBatisUtils.close();
        return users;

    }
}
